package com.muje.android.toiletcard;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class PlayerSetupActivity extends Activity {

	private Button okPlayerButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.player);

		okPlayerButton = (Button) this.findViewById(R.id.okPlayerButton);
		okPlayerButton.setOnClickListener(doneOnClick);
	}

	protected OnClickListener doneOnClick = new OnClickListener() {

		public void onClick(View v) {
			start();
		}
	};

	private void configurePlayer() {
		
		DisplayActivity.poker = new Poker(this);

		EditText editText1 = (EditText) this.findViewById(R.id.editText1);
		EditText editText2 = (EditText) this.findViewById(R.id.editText2);
		EditText editText3 = (EditText) this.findViewById(R.id.editText3);
		EditText editText4 = (EditText) this.findViewById(R.id.editText4);
		EditText editText5 = (EditText) this.findViewById(R.id.editText5);
		EditText editText6 = (EditText) this.findViewById(R.id.editText6);
		EditText editText7 = (EditText) this.findViewById(R.id.editText7);
		EditText editText8 = (EditText) this.findViewById(R.id.editText8);
		EditText editText9 = (EditText) this.findViewById(R.id.editText9);
		EditText editText10 = (EditText) this.findViewById(R.id.editText10);
		EditText editText11 = (EditText) this.findViewById(R.id.editText11);
		EditText editText12 = (EditText) this.findViewById(R.id.editText12);
		EditText[] texts = new EditText[] { editText1, editText2, editText3,
				editText4, editText5, editText6, editText7, editText8,
				editText9, editText10, editText11, editText12 };

		for (int i = 0; i < texts.length; i++) {
			if (texts[i].getText().toString().trim().length() == 0) {
				DisplayActivity.poker.addPlayer(null);
			} else {
				Player player = new Player(texts[i].getText().toString().trim());
				DisplayActivity.poker.addPlayer(player);
			}
		}
	}

	private void start() {

		configurePlayer();
		startActivity(new Intent(this, DisplayActivity.class));
		finish();
	}

}